/**
* @params baseUrl: 接口路径
* @params data: 请求参数
* @params success：请求成功的回调
* @params fail：请求失败的回调
* @params Api：接口
*/
const GET = 'GET';
const POST = 'POST';
// const baseUrl = 'http://120.46.185.194:9005/api/doc/v1/';
const baseUrl = 'https://umpadmin.hn-talent.com/prod_api/api/doc/v1/';

function request(method, url, data) {
	return new Promise((resolve, reject) => {
		let header = {
		    'content-type': 'application/json' 
		};
		wx.request({
			url: baseUrl + url,
			method: method,
			header: header,
      data: method === POST ? JSON.stringify(data) : data,
			success: (res) => {
				if(res.data.code === 200){
					resolve(res.data.result);
				} else {
					reject(res.data);
				}
			},
			fail: (err) => {
				reject(err);
			}
		})
	})
}
const Api = {
  getHomeGoods:(data) => request(GET, 'getHomeGoods?pageNo=0&pageSize=10'),
  getGoods:(data) => request(GET, 'getGoods?goodsId='+data),
  getGoodsList: (data) => request(GET, 'getGoodsList?goodsType='+data),
  getBanners: (data) => request(GET, 'getBanners', data),
  getGoodsTypes:(data) => request(GET, 'getGoodsTypes', data),
  createOrder: (data) => request(POST, 'createOrder', data),
  calcPrePrice: (data) => request(POST, 'calcPrePrice', data),
  getOrdersByOpenId: (data) => request(GET, 'getOrders?openId='+data),
  getOrdersByOpenIdAndOrderId: (data,data1) => request(GET, 'getOrders?openId='+data+'&orderId='+data1),
	getOrderLog: (data) => request(GET, 'getOrderLog?orderId='+data),
  confirmOrder: (data) => request(POST, 'confirmOrder?orderId='+data, data),
  getPreviewImage: (data) => request(GET, 'getPreviewImage?fileNo='+data),
  getOpenId: (data) => request(GET, 'getOpenId?code='+data),
  getPhoneNumber: (data) => request(GET, 'getPhoneNumber?code='+data),
};
module.exports = {
	Api
}
